package com.bayes.teamshow.controller;

import com.alibaba.fastjson.JSONObject;
import com.bayes.teamshow.dao.IUserDAO;
import com.bayes.teamshow.pojo.UserLwwen;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;

@Controller
@RequestMapping("/myCenter")
public class myCenterController {
	@Autowired
	IUserDAO userDAO;

	@RequestMapping("")
	public String getMyCenter() {
		return "myCenter";
	}

	@RequestMapping(value = "/user", method = RequestMethod.GET)
	@ResponseBody
	public Object getUser(@RequestParam("userid")int id, HttpServletRequest request) {
		UserLwwen userLwwen = userDAO.findById(id);
//		UserLwwen userLwwen = userDAO.findById(1000);
		JSONObject userjson = new JSONObject();
		JSONObject data = new JSONObject();
		data.put("title",userLwwen.getUsername());
		data.put("year",userLwwen.getGrade());
		data.put("name", userLwwen.getName());
		data.put("mail",userLwwen.getMail());
		data.put("myIcon", userLwwen.getPicture_url());
		data.put("nativeplace",userLwwen.getNativeplace());
		data.put("gender", userLwwen.getSex());
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		data.put("birthday",df.format(userLwwen.getBirthday()));
		data.put("sign",userLwwen.getSelfdescription());
		userjson.put("user", data);
		return userjson;
	}
}
